from flask import render_template
from flask_mail import Message
from app import mail, app
from app.forms import ResetPasswordForm


def send_email(subject,sender,recipients,text_body,html_body):
    msg =Message(subject,sender=sender,recipients=recipients)
    msg.body =text_body
    msg.html =html_body

    mail.send(msg)

def send_password_reset_email(user):
    token = user.get_reset_password_token()
    form = ResetPasswordForm()
    send_email(subject='RESET YOUR PASSWORD',
                sender=app.config['MAIL_USERNAME'],
                recipients=[user.email],
                text_body=render_template('reset_password.txt',
                             user=user,token=token),
                html_body=render_template('rp.html',
                             user=user,token=token))

